/**************************************************************************
 *  创建者：        华磊
 *  开始时间：   2019.05.3
 *  copyright:  (C) 深圳市华友高科有限公司
 *  修改说明：  (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 *
 ***************************************************************************/
#include "axismoveinstructionview.h"
#include "ui_axismoveinstructionview.h"
#include <QMessageBox>

AxisMoveInstructionView::AxisMoveInstructionView(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AxisMoveInstructionView)
{
    ui->setupUi(this);
    setGeometry(5,50,451,544);
    initialDisplayStyle(styleId);
    ui->rate_slider_velocity->setMaximum(100);
    ui->rate_slider_velocity->setMinimum(0);

    ui->comboBox_axisId->insertItem(0,"无");
    for(int i=0;i<D_ROBOT_AXIS_MAX;i++)
    {
        QString tmpStr;
        tmpStr="J";
        tmpStr+=QString::number(i+1);
        ui->comboBox_axisId->insertItem(i+1,tmpStr);
    }
}

void AxisMoveInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->note_GBox->hide();
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

AxisMoveInstructionView::~AxisMoveInstructionView()
{
    delete ui;
}

void AxisMoveInstructionView::getInput()
{
    instructionPara.axisId=ui->comboBox_axisId->currentIndex();
    instructionPara.velocityRatio=ui->rate_slider_velocity->value();
    instructionPara.rateUnitTypeFlag=E_RATE_PERCENT;
    instructionPara.targetPosition=ui->lineEdit_targetPosition->text().toDouble();
    instructionPara.comment=ui->note_lineEdit->text();
    instructionPara.positionReference=(E_POSITION_REFERENCE)ui->comboBox_positionType->currentIndex();
}

void AxisMoveInstructionView::updateView()
{
    ui->comboBox_axisId->setCurrentIndex(instructionPara.axisId);
    ui->rate_slider_velocity->setValue(instructionPara.velocityRatio);
    ui->lineEdit_targetPosition->setText(QString::number(instructionPara.targetPosition));
    ui->note_lineEdit->setText(instructionPara.comment);
    ui->comboBox_positionType->setCurrentIndex(instructionPara.positionReference);
    ui->rate_lineEdit_2->setText(QString::number(instructionPara.velocityRatio));
}

void AxisMoveInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->setText("");
}

void AxisMoveInstructionView::on_save_Btn_clicked()
{
    getInput();
    emit finishEditInstructionSignal();
    emit saveInstructionSignal(instructionStr);
}

void AxisMoveInstructionView::on_rate_slider_velocity_sliderMoved(int position)
{
    ui->rate_lineEdit_2->setText(QString::number(position));
}

void AxisMoveInstructionView::on_pushButton_manualDisableAxisFollowFunction_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否立刻解除当前轴跟随功能！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    emit setCoupleControl_signal(ui->comboBox_axisId->currentIndex()-1 ,false );
}

void AxisMoveInstructionView::on_pushButton_manualEnableAxisFollowFunction_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否立刻使能当前轴跟随功能！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    emit setCoupleControl_signal(ui->comboBox_axisId->currentIndex()-1 ,true );
}

void AxisMoveInstructionView::on_forward_Btn_clicked()
{
    getInput();
    emit finishEditInstructionSignal();
    emit saveInstructionSignal(instructionStr);
}
